package com.xoa.controller.event;

import com.xoa.model.event.*;
import com.xoa.service.event.TimeLineService;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 张丽军 on 2017/8/30.
 * 大事记管理数据接口控制器
 */
@RestController
@RequestMapping("/timeLine")
public class TimeLineController {
    @Autowired
    TimeLineService timeLineService;

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-8-31 上午11:22:25
     * 方法介绍:   根据uuid查看详情
     * @param request
     * @param uuid
     * @return
     */

    @ResponseBody
    @RequestMapping("/getDetailByUuid")
    public ToJson<TimeLine> getDetailByUuid(HttpServletRequest request,String uuid){
        return timeLineService.getDetailByUuid(request,uuid);
    }

    /**
     * 创建作者:   杨超
     * 创建日期:   2017-9-26
     * 方法介绍:   根据uuid查看详情
     * @param request
     * @param uuid
     * @return
     */
    @ResponseBody
    @RequestMapping("/getTimeLineByUuid")
    public ToJson<TimeLine> getTimeLineByUuid(HttpServletRequest request,String uuid){
        return timeLineService.getTimeLineByUuid(request,uuid);
    }


    /**
     * 获取大事记类型及编码
     * @auth: 杨超
     * @param request
     * @param uuid
     * @return
     */
    @ResponseBody
    @RequestMapping("/getTimeLineCode")
    public ToJson<Object> getTimeLineCode(HttpServletRequest request,String uuid){
        return timeLineService.getTimelineCode(request,uuid);
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-8-31 上午11:22:25
     * 方法介绍:   查看列表所有信息和高级条件搜索（大事记）
     * @param request
     * @param timeLine
     * @return
     */
    @ResponseBody
    @RequestMapping("/getInforList")
    public ToJson<TimeLine> getInforList(HttpServletRequest request,TimeLine timeLine){
        return timeLineService.getInforList(request,timeLine);
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-8-31 上午11:22:25
     * 方法介绍:   查看列表所有信息和高级条件搜索（管理）
     * @param request
     * @param timeLine
     * @return
     */
    @ResponseBody
    @RequestMapping("/getInforList1")
    public ToJson<TimeLine> getInforList1(HttpServletRequest request,TimeLine timeLine){
        return timeLineService.getInforList1(request,timeLine);
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-09-01 下午15:42:25
     * 方法介绍:   修改信息
     * @param request
     * @param timeLine
     * @param post1
     * @param post2
     * @param post3
     * @param view1
     * @param view2
     * @param view3
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateData")
    public ToJson<TimeLine> updateData(HttpServletRequest request, TimeLine timeLine,TimeLinePostDept timeLinePostDept,
                                       TimeLinePostRole timeLinePostRole,TimeLinePostUser timeLinePostUser,
                                       TimeLineViewDept timeLineViewDept,TimeLineViewRole timeLineViewRole,TimeLineViewUser timeLineViewUser,
                                       String post1,String post2,String post3,String view1,String view2,String view3){
        return timeLineService.updateData(request,timeLine,timeLinePostDept,timeLinePostRole,timeLinePostUser,timeLineViewDept,timeLineViewRole,timeLineViewUser,post1,post2,post3,view1,view2,view3);
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-09-01 下午16:12:25
     * 方法介绍:   新建信息
     * @param request
     * @param timeLine
     * @param post1
     * @param post2
     * @param post3
     * @param view1
     * @param view2
     * @param view3
     * @return
     */
    @ResponseBody
    @RequestMapping("/addData")
    public ToJson<TimeLine> addData(HttpServletRequest request, TimeLine timeLine,String post1,String post2,String post3,String view1,String view2,String view3){
        return timeLineService.addData(request,timeLine, post1,post2,post3,view1,view2,view3);
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-8-31 下午14:08:25
     * 方法介绍:   根据uuid删除信息
     * @param request
     * @param uuid
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteByUuid")
    public ToJson<TimeLine> deleteByUuid(HttpServletRequest request,String uuid){
        return timeLineService.deleteByUuid(request,uuid);
    }

    /**
     * 获取当前用户具有查看权限的所有大事记
     * @auth:杨超
     * @time:2017-09-25
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/getTimelines")
    public ToJson<TimeLine> getTimelines(HttpServletRequest request) throws UnsupportedEncodingException {
        ToJson<TimeLine>  json = new ToJson<>();
        json.setObj(timeLineService.getTimelines(request));
        json.setFlag(0);
        json.setMsg("ok");
        return json;
    }

    @ResponseBody
    @RequestMapping("/getPageTimelines")
    public ToJson<TimeLine> getPageTimelines(HttpServletRequest request,PageParams page, String title,String tag) throws UnsupportedEncodingException {
        ToJson<TimeLine>  json = new ToJson<>();
        Map<String,Object> map  =new HashMap<>();
        map.put("title",title);
        map.put("tag",tag);
        json.setObj(timeLineService.getPageTimelines(request,page,map));
        json.setFlag(0);
        json.setMsg("ok");
        return json;
    }

    /**
     * 获取当前用户具有修改权限的所有大事记
     * @auth:杨超
     * @time:2017-09-25
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/postPageTimelines")
    public ToJson<TimeLine> postPageTimelines(HttpServletRequest request,PageParams page, String title,String tag) throws UnsupportedEncodingException {
        ToJson<TimeLine>  json = new ToJson<>();
        Map<String,Object> map  =new HashMap<>();
        json.setObj(timeLineService.postTimelines(request,page,null));
        json.setFlag(0);
        json.setMsg("ok");
        return json;
    }


}
